import { defineFakeRoute } from "vite-plugin-fake-server/client";

export default defineFakeRoute([
  {
    // 这个接口会返回一个 7 天内注册量 的数据，比如：
    // {
    //   "days": ["周1", "周2", ..., "周7"],
    //   "values": [123, 456, 789, ...]
    // }
    url: "/api/chart/register-trend",
    method: "get",
    response: () => {
      const days = Array.from({ length: 7 }, (_, i) => `周${i + 1}`);
      const data = days.map(() => Math.floor(Math.random() * 1000 + 100));
      return {
        code: 0,
        data: {
          days,
          values: data,
        },
      };
    },
  },
  {
    url: "/api/chart/map",
    method: "get",
    response: () => {
      const provinces = [
        "广东",
        "江苏",
        "北京",
        "浙江",
        "山东",
        "四川",
        "河南",
        "湖南",
      ];
      const data = provinces.map((name) => ({
        name,
        value: Math.floor(Math.random() * 1000),
      }));
      return {
        code: 0,
        data,
      };
    },
  },
  {
    url: "/api/chart/system-status",
    method: "get",
    response: () => ({
      code: 0,
      data: [
        { name: "CPU", value: Math.floor(Math.random() * 100) },
        { name: "内存", value: Math.floor(Math.random() * 100) },
        { name: "磁盘", value: Math.floor(Math.random() * 100) },
      ],
    }),
  },
  {
    url: "/api/chart/activity-rank",
    method: "get",
    response: () => {
      const list = [
        "开学典礼",
        "元宵活动",
        "春季团建",
        "安全演练",
        "招聘宣讲",
        "编程大赛",
      ];
      const data = list
        .map((name) => ({
          name,
          value: Math.floor(Math.random() * 5000 + 500), // 随机 500-5500
        }))
        .sort((a, b) => b.value - a.value); // 按热度倒序排列
      return {
        code: 0,
        data,
      };
    },
  },
  {
    url: "/api/chart/user-distribution",
    method: "get",
    response: () => ({
      code: 0,
      data: {
        gender: [
          { name: "男", value: Math.floor(Math.random() * 5000 + 1000) },
          { name: "女", value: Math.floor(Math.random() * 5000 + 1000) },
        ],
        region: [
          { name: "广东", value: Math.floor(Math.random() * 2000) },
          { name: "江苏", value: Math.floor(Math.random() * 2000) },
          { name: "山东", value: Math.floor(Math.random() * 2000) },
          { name: "湖南", value: Math.floor(Math.random() * 2000) },
        ],
      },
    }),
  },
  {
    url: "/api/chart/active-users",
    method: "get",
    response: () => ({
      code: 0,
      data: {
        activeUsers: Math.floor(Math.random() * 5000 + 500), // 500 ~ 5500
      },
    }),
  },
]);
